<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${pro.basePath!}.mappers.${bean.entityName!}Mapper">
	<resultMap id="BaseResultMap"  type="${bean.entityName?uncap_first}">
	   [#list bean.fields as field][#if field.iskey]
       <id column="${field.columnName!}" property="${field.fieldName!}"/>[#else]
        <result column="${field.columnName!}" property="${field.fieldName!}" />[/#if][/#list]
	</resultMap>
	<sql id="Base_Column_List">
	    [#list bean.fields as field]${field.columnName!}[#if field_has_next],[/#if][/#list]
	</sql>
	<insert id="insertIncludeNull" parameterType="${bean.entityName?uncap_first}" useGeneratedKeys="true"  keyProperty="${bean.idName}">
		insert into ${bean.tableName!} (  
		[#list bean.fields as field]${field.columnName!}[#if field_has_next],[/#if][/#list]
		)
		values ( 
		[#list bean.fields as field] ${r' #{'}${field.fieldName!}}[#if field_has_next],[/#if][/#list]
		)
	</insert>
	<insert id="insert" parameterType="${bean.entityName?uncap_first}" useGeneratedKeys="true"  keyProperty="${bean.idName}">
		insert into ${bean.tableName!}
	   <trim prefix="(" suffix=")" suffixOverrides="," >
	   [#list bean.fields as field]
      <if test="null!=${field.fieldName!}" >
        ${field.columnName!},
      </if>
      [/#list]
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      [#list bean.fields as field]
      <if test="null!=${field.fieldName!}" >
        ${r' #{'}${field.fieldName!}},
      </if>
      [/#list]
    </trim>
	</insert>
	<update id="updateById" parameterType="${bean.entityName?uncap_first}">
		update ${bean.tableName!} 
		<set>
			[#list bean.fields as field]
			<if test="null!=${field.fieldName!}">
				${field.columnName!} = ${r' #{'}${field.fieldName!}},
			</if>
			[/#list]
		</set>
		where ${bean.idName!} = ${r' #{'}${bean.idName!}}
	</update>
	<update id="updateByIdIncludeNull" parameterType="${bean.entityName?uncap_first}" >
       update ${bean.tableName!}  set
       [#list bean.fields as field]
        ${field.columnName!} = ${r' #{'}${field.fieldName!}}[#if field_has_next],[/#if]
       [/#list]
      	where ${bean.idName!} = ${r' #{'}${bean.idName!}}
    </update>
	<delete id="deleteById" parameterType="java.lang.Integer">
		update  ${bean.tableName!}  set isDelete=1
    	where ${bean.idName!} = ${r' #{'}${bean.idName!}}
	</delete>
	<select id="queryById" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from ${bean.tableName!}
		where ${bean.idName!} = ${r' #{'}${bean.idName!}}
	</select>
	<sql id="where_sql">
     	[#list bean.fields as field]
		<if test="null!=param.${field.fieldName!}">
			and ${field.columnName!} = ${r' #{'}param.${field.fieldName!}}
		</if>
	     [/#list]
	</sql>
	<select id="queryList" resultMap="BaseResultMap" parameterType="java.util.Map">
		select
		<include refid="Base_Column_List" />
		from ${bean.tableName!}
		<where>
			<include refid="where_sql"></include>
		</where>
	</select>
	<select id="queryPage" resultMap="BaseResultMap" parameterType="java.util.Map">
		select
		<include refid="Base_Column_List" />
		from ${bean.tableName!}
		<where>
			<include refid="where_sql"></include>
		</where>
		limit ${r' #{'}page.offset},${r' #{'}page.size}
	</select>
	<select id="queryPageCount" resultType="Integer" parameterType="java.util.Map">
		select
	    count(1)
		from ${bean.tableName!}
		<where>
			<include refid="where_sql"></include>
		</where>
	</select>
</mapper>